<template>
  <div class="column-list row">
    <div class="col-4 mb-3" v-for="item in columnList" :key="item.id">
      <div class="card shadow-sm">
        <div class="card-body text-center">
          <img
            :src="item.avatar"
            class="avatar rounded-circle border border-light my-3"
            :alt="item.title"
          />
          <h5 class="card-title">{{ item.title }}</h5>
          <p class="card-text text-truncate">{{ item.description }}</p>
          <a href="#" class="btn btn-outline-primary">进入专栏</a>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, PropType } from 'vue'

export interface ColumnProp {
  id: number;
  title: string;
  avatar?: string;
  description: string;
}

export default defineComponent({
  name: 'ColumnList',
  props: {
    list: {
      type: Array as PropType<ColumnProp[]>,
      required: true
    }
  },
  setup (props) {
    // 列表
    const columnList = computed(() => {
      return props.list.map((item) => {
        if (!item.avatar) item.avatar = require('@/assets/default-avatar.png')
        return item
      })
    })
    return {
      columnList
    }
  }
})
</script>

<style lang="scss">
.column-list {
  .avatar {
    width: 80px;
    height: 80px;
    object-fit: cover;
  }

  .card-text {
    text-align: left;
  }
}
</style>
